package com.zyit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyit.dto.HospitalDto;
import com.zyit.mapper.*;
import com.zyit.pojo.Hospital;
import com.zyit.service.HospitalService;
import com.zyit.util.Result;
import com.zyit.vo.HospitalVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalMapper hospitalMapper;

    @Override
    public int add(Hospital hospital) {
        return hospitalMapper.insert(hospital);
    }

    @Override
    public int edit(Hospital hospital) {
        return hospitalMapper.updateById(hospital);
    }

    @Override
    public Hospital findById(Long id) {
        return hospitalMapper.selectById(id);
    }

    @Override
    public Result findPage(HospitalDto hospitalDto) {
        hospitalDto.setPage((hospitalDto.getPage()-1)*hospitalDto.getLimit());
        int count = hospitalMapper.getCount(hospitalDto);
        List<HospitalVo> list = hospitalMapper.findAll(hospitalDto);
        return new Result("200","",list,count);
    }

    @Override
    public Hospital findByCode(String hoscode) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("hoscode",hoscode);
        return hospitalMapper.selectOne(wrapper);
    }


}
